const mysql = require('mysql');

let connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '123',
    port: '3306',
    database: 'web3'
});

connection.connect();

let selectSql = 'SELECT id,name FROM test';

connection.query(selectSql, function(err, result) {
    if(err) {
        console.log('[SELECT ERROR] - ', err.message);
        return;
    }

    console.log('--------------------------SELECT----------------------------');
    console.log(result);
    console.log('------------------------------------------------------------\n\n');
});


// let addSql = 'INSERT INTO test(id,name) VALUES(0,?)';
// let addSqlParams = ['赵六'];
// connection.query(addSql, addSqlParams, function(err, result) {
//     if(err) {
//         console.log('[INSERT ERROR] - ', err.message);
//         return;
//     }
//     console.log('--------------------------INSERT----------------------------');
//     console.log('INSERT ID:', result);
//     console.log('-----------------------------------------------------------------\n\n');
// });

// let delSql = 'DELETE FROM test where id = 5';

// connection.query(delSql, function(err, result) {
//     if(err) {
//         console.log('[DELETE ERROR] - ', err.message);
//         return;
//     }

//     console.log('--------------------------DELETE----------------------------');
//     console.log('DELETE affectedRows', result.affectedRows);
//     console.log('-----------------------------------------------------------------\n\n');
// });


/* let updateSql = 'UPDATE test SET name = ? WHERE id = ?';
let SqlParams = ['袅袅娜娜', '4'];
//改
connection.query(updateSql, SqlParams, function(err, result) {
    if(err) {
        console.log('[UPDATE ERROR] - ', err.message);
        return;
    }
    console.log('--------------------------UPDATE----------------------------');
    console.log('UPDATE affectedRows', result.affectedRows);
    console.log('-----------------------------------------------------------------\n\n');
});
 */
connection.end();